package com.baosight.risk.service.riim.impl;

import com.baosight.risk.api.riim.RiimRiskGoalDetailService;
import com.baosight.risk.base.service.BaseServiceImpl;
import com.baosight.risk.common.bean.BeanUtils;
import com.baosight.risk.common.utils.StringUtils;
import com.baosight.risk.mapper.riim.RiimRiskGoalDetailMapper;
import com.baosight.risk.service.riim.entity.RiimRiskGoalDetail;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * @author RayWade
 * @create 2019-12-17 14:26
 */
@Service
@Slf4j
public class RiimRiskGoalDetailServiceImpl extends BaseServiceImpl<RiimRiskGoalDetail> implements RiimRiskGoalDetailService {

    @Autowired
    private RiimRiskGoalDetailMapper riskGoalDetailMapper;

    @Override
    public Integer saveRiskGoalDetail(List<RiimRiskGoalDetail> goalDetailList) {
        for (RiimRiskGoalDetail goalDetail : goalDetailList) {
            if (StringUtils.isNotEmpty(goalDetail.getId())) {
                goalDetail = (RiimRiskGoalDetail) BeanUtils.updateBean(goalDetail);
                update(goalDetail);
            } else {
                goalDetail = (RiimRiskGoalDetail) BeanUtils.initBean(goalDetail);
                riskGoalDetailMapper.insert(goalDetail);
            }
        }
        return 1;
    }

    @Override
    public void deleteRiskGoalDetail(List<String> ids) {
        ids.forEach( id ->
                riskGoalDetailMapper.deleteByPrimaryKey(id)
        );
    }
}
